<template>
    <div>
      <h1>过车记录</h1>
      <h1>总数：{{ VehWareList.length }}</h1>
      <el-input
        placeholder="请输入车牌号"
        v-model="sqResidenceRequest.vehicleInformationName"
        clearable
        @clear="getVehWareList"
        @keyup.enter.native="getVehWareList"
        style="width: 200px;">
      </el-input>
      <el-button type="primary" @click="getVehWareList">查询</el-button>
      <hr style="border: 0; border-top: 1px dashed #5a5e66;">
      <h5>共{{ VehWareList.length }}条信息</h5>

      <el-row>
        <el-col :span="4"  v-for="(war, index) in VehWareList" :key="war.id" :offset="index > 0 ? 2 : 0">
          <el-card
            class="card-container"
            :class="{ 'card-selected': selectedResidenceIndex === index }"
          >
            <div
              style="width: 100%;height: 100%;"
              @click="selectResidence(index)"
            >

              <div class="card-content">
                <div class="image-wrapper">
                  <img
                    :src="war.vehicleInformationPic  "
                    class="image">
                  <br>
                  <h2>
                  车牌号:{{war.vehicleInformationName}} <br>
                  进出: {{ (war.vehicleWarehouseCome == 1) ? '进入' : ((war.vehicleWarehouseCome == 2) ? '离开' : '未知') }}<br>
                  抓拍时间:{{war.vehicleWarehouseTime}} <br>
                  关卡:{{war.monitoringInstallationSite}}<br>
                    <el-button size="mini" @click="handleEdit(war.vehicleInformationId)">详情</el-button>
                  </h2>
                </div>
              </div>
            </div>
          </el-card>
        </el-col>


            <!-- 弹出 -->
            <el-button type="text" @click="windows">弹窗</el-button>
            <el-dialog :title=title :visible.sync="dialogFormVisible">
              <el-form :model="form">
                <el-form-item label="车牌号" :label-width="formLabelWidth">
                  <el-input v-model="form.vehicleInformationName" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="抓拍时间" :label-width="formLabelWidth">
                  <el-input v-model="form.vehicleWarehouseTime" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="抓拍地点" :label-width="formLabelWidth">
                  <el-input v-model="form.monitoringInstallationSite" autocomplete="off"></el-input>
                </el-form-item>
                <el-dialog :visible.sync="dialogVisible">
                  <img width="30px" height="40px" :src="dialogImageUrl" alt="">
                </el-dialog>
              </el-form>
              <div slot="footer" class="dialog-footer">
                <el-button @click="dialogFormVisible = false">取 消</el-button>
                <el-button type="primary" @click="dialogFormVisible = false">确 定</el-button>
              </div>
            </el-dialog>

      </el-row>
      <div class="fen">
        <span class="demonstration">分页</span>
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="sqResidenceRequest.pageNum"
          :page-sizes="[10, 20, 30, 50]"
          :page-size="sqResidenceRequest.pageSize"
          layout="sizes, prev, pager, next"
          :total="total">
        </el-pagination>
      </div>
    </div>

</template>

<script>
//这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）,
//例如：import 《组件名称》 from '《组件路径》,
import {echo, warList} from '@/api/monitor/vehware'
export default {
  //import引入的组件需要注入到对象中才能使用"
  components: {},
  props: {},
  data() {
    //这里存放数据"
    return {
      //遮罩层显示
      VehWareList: [],
      loadingText: true,

      total:0,
      //表格树结构
      war: [],
      //是否展开,默认全部展开
      isExpandAll:true,
      //分页
      sqResidenceRequest:{
        vehicleInformationName: "",
        pageNum: 1,
        pageSize: 10,
      },
      //弹出
      title:'回显详情',
      dialogTableVisible: false,
      dialogFormVisible: false,
      //图片
      dialogImageUrl: '',
      dialogVisible: false,
      //弹出内容
      form:{
        vehicleInformationName:'',
        vehicleWarehouseCome:'',
        vehicleWarehouseTime:'',
        monitoringInstallationSite:'',
      },
      formLabelWidth: '120px',
      selectedResidenceIndex: 0,


    };
  },
  //计算属性 类似于data概念",
  computed: {},
  //监控data中的数据变化",
  watch: {},
  //方法集合",
  methods: {
    //列表查询
    getVehWareList(){
      warList(this.sqResidenceRequest).then(
        res=> {
          this.VehWareList =res.data.rows
          this.total=res.data.total
        }
      )
    },

    //回显
    handleEdit(vehicleInformationId){
      this.title='回显车辆'
      this.dialogFormVisible = true;
      echo(vehicleInformationId).then(
        res => {
          this.form=res.data
        }
      )
    },

    //弹窗
    windows(){
      this.dialogFormVisible = true
      this.VehWareList={
        vehicleInformationName:'',
        vehicleWarehouseCome:'',
        vehicleWarehouseTime:'',
        monitoringInstallationSite:'',
      }
    },

    //更新选中的图片
    selectResidence(index){
      this.selectedResidenceIndex = index; // 更新选中的卡片索引
    },

    //分页
    handleSizeChange(val) {
      this.sqResidenceRequest.pageNum=val
      console.log(`每页 ${val} 条`);
      this.getVehWareList()
    },
    handleCurrentChange(val) {
      this.sqResidenceRequest.pageSize=val
      console.log(`当前页: ${val}`);
      this.getVehWareList()
    },
  },
  //生命周期 - 创建完成（可以访问当前this实例）",
  created() {
    this.getVehWareList();
  },
  //生命周期 - 挂载完成（可以访问DOM元素）",
  mounted() {
  },
  beforeCreate() {
  }, //生命周期 - 创建之前",
  beforeMount() {
  }, //生命周期 - 挂载之前",
  beforeUpdate() {
  }, //生命周期 - 更新之前",
  updated() {
  }, //生命周期 - 更新之后",
  beforeDestroy() {
  }, //生命周期 - 销毁之前",
  destroyed() {
  }, //生命周期 - 销毁完成",
  activated() {
  } //如果页面有keep-alive缓存功能，这个函数会触发",
};
</script>
<style scoped>
.card-container{
  height: 350px;
  width: 450px;
  display: flex;
  flex-direction: column; /* 保持卡片内容的垂直布局 */
  align-items: center; /* 如果需要，可以垂直居中 */
  justify-content: center; /* 如果需要，可以水平居中（但在这个案例中不是必需的） */
  padding: 16px; /* 给卡片内部添加一些内边距 */
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1); /* 添加卡片阴影，使样式更美观 */
  border-radius: 8px; /* 添加圆角 */
  background-color: #15559a; /* 设置背景颜色 */
}
.card-selected{
  /* 选中卡片的样式，例如边框颜色变化、背景颜色变化等 */
  border: 2px solid #158bb8; /* Element UI的主题色 */
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
}
.card-content{
  display: flex;
  /*保持子元素垂直居中*/
  align-items: center;
  width: 100%;
}


.image-wrapper {
  flex: 0 0 auto; /* 图片容器占据固定空间 */
  margin-right: 16px; /* 图片和信息之间的间距 */
}

.image {
  max-width: 200px; /* 限制图片的最大宽度 */
  max-height: 150px; /* 限制图片的最大高度，保持宽高比可以通过object-fit处理 */
  object-fit: cover; /* 保持图片的纵横比并填充容器 */
  border-radius: 8px; /* 添加圆角 */
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); /* 添加图片阴影 */
}

.info-wrapper {
  flex: 1 1 auto; /* 信息容器占据剩余空间 */
  display: flex;
  flex-direction: column; /* 信息内容垂直排列 */
  align-items: flex-start; /* 信息内容从左侧开始排列 */
}

.title {
  font-size: 16px; /* 设置标题字体大小 */
  font-weight: bold; /* 设置标题字体加粗 */
  margin-bottom: 8px; /* 标题和底部信息之间的间距 */
}

.bottom-info {
  display: flex;
  align-items: center; /* 底部信息垂直居中 */
}
</style>
